//
//  ShreConfig.m
//  XPhoto
//
//  Created by baboy on 2019/10/21.
//  Copyright © 2019 baboy. All rights reserved.
//

#import "ShareUtil.h"

@implementation ShareUtil

+ (void)configShareSetting{
    [UMSocialGlobal shareInstance].isUsingHttpsWhenShareContent = NO;
}
+ (void)configSharePlatforms{
    NSArray *platforms = [NSArray arrayWithContentsOfFile:getBundleFilePath(@"share.conf.plist", nil)];
    for (NSDictionary *platform in platforms) {
        NSInteger platformId = [[platform valueForKey:@"id"] integerValue];
        NSString *appKey = [platform valueForKey:@"appKey"];
        NSString *appSecret = [platform valueForKey:@"appSecret"];
        NSString *redirectURL = [platform valueForKey:@"redirectURL"];
        [[UMSocialManager defaultManager] setPlaform:(UMSocialPlatformType)platformId appKey:appKey appSecret:appSecret redirectURL:redirectURL];
    }
}
+ (void)loginFromPlatform:(UMSocialPlatformType)platform callback:(void(^)(id result, NSError* error)) callback{
    [[UMSocialManager defaultManager] getUserInfoWithPlatform:platform currentViewController:nil completion:^(id result, NSError *error) {
        if (error) {
            DLOG(@"error:%@", error);
        } else {
            UMSocialUserInfoResponse *resp = result;
            // 授权信息
            NSLog(@"Wechat uid: %@", resp.uid);
            NSLog(@"Wechat openid: %@", resp.openid);
            NSLog(@"Wechat unionid: %@", resp.unionId);
            NSLog(@"Wechat accessToken: %@", resp.accessToken);
            NSLog(@"Wechat refreshToken: %@", resp.refreshToken);
            NSLog(@"Wechat expiration: %@", resp.expiration);
            // 用户信息
            NSLog(@"Wechat name: %@", resp.name);
            NSLog(@"Wechat iconurl: %@", resp.iconurl);
            NSLog(@"Wechat gender: %@", resp.unionGender);
            // 第三方平台SDK源数据
            NSLog(@"Wechat originalResponse: %@", resp.originalResponse);
        }
    }];
}
@end
